//获取应用实例
const app = getApp()

Page({
  data:{
    page:[],
    objectArray: [],
    index: 0,
    name:"",
    list:{},  

  },




  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'https://gdzc.sxpmg.com/shuhai/Peoplecon.do',
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        name: that.data.name,
        page:0,
      },

      success: function (res) {
       console.log(res)

        that.setData({
          page: res.data.count,
          objectArray: res.data.objectArray,
          index: res.data.index,
          list:res.data.list
        })
      } 
  })
  },


  //选这页数
 
  bindchangePage: function (e) {
    var that = this;
    this.setData({
      index: e.detail.value+1
    })
    wx.request({
      url: 'https://gdzc.sxpmg.com/shuhai/Peoplecon.do',
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        name: that.data.name,
        page: e.detail.value,
      },
      success: function (res) {
        console.log(res)

        that.setData({
          page: res.data.count,
          objectArray: res.data.objectArray,
          list: res.data.list,
          index: res.data.index
        })
      }
    })
  
  },



  searchBox: function (e) {
    var that = this;
    console.log('form发生了submit事件，携带数据为：', e.detail.value.name)
    this.setData({
      name: e.detail.value.name
    })
    wx.request({
      url: 'https://gdzc.sxpmg.com/shuhai/Peoplecon.do',
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        name: e.detail.value.name,
        page: 0,
      },
      success: function (res) {
        console.log(res)

        that.setData({
          page: res.data.count,
          objectArray: res.data.objectArray,
          index: res.data.index,
          list: res.data.list
        })
      }
    })


  },


// 上一页

  previousp: function(e){
    var that = this;
    console.log("上一页" + e.currentTarget.dataset.lockerid)

    if (e.currentTarget.dataset.lockerid-1 < 0) {
      this.setData({
        index: 0,
      })
    } else {
      this.setData({
        index: e.currentTarget.dataset.lockerid - 1.
      })
    }
    wx.request({
      url: 'https://gdzc.sxpmg.com/shuhai/Peoplecon.do',
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        name: that.data.name,
        page: e.currentTarget.dataset.lockerid - 1,
      },
      success: function (res) {
        console.log(res)

        that.setData({
          page: res.data.count,
          objectArray: res.data.objectArray,
          list: res.data.list
          
        })
      }
    })

  },


//下一页
  previouspxyi:function(e){
    console.log("下一页" + e.currentTarget.dataset.lockerid)
    var that = this;

    // this.setData({
    //   index: e.currentTarget.dataset.lockerid + 1.
    // })
    wx.request({
      url: 'https://gdzc.sxpmg.com/shuhai/Peoplecon.do',
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        name: that.data.name,
        page: e.currentTarget.dataset.lockerid + 1,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          page: res.data.count,
          objectArray: res.data.objectArray,
          list: res.data.list,
          index: res.data.index
        })
      }
    })

  },

  




})